import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_common/ui/dialog/select_bottom_sheet.dart';
import 'package:flutter_common/ui/list/left_right_text.dart';
import 'package:flutter_common/ui/list/single_list_item.dart';
import 'package:flutter_common/ui/list/text_input.dart';
import 'package:flutter_common/ui/list/text_select.dart';
import 'package:flutter_common/ui/scaffold.dart';
import 'package:flutter_common/util/string_utils.dart';
import 'package:flutter_common/util/toast_util.dart';

class ListItemDemo extends StatelessWidget {

  ValueNotifier<String> select = ValueNotifier<String>('');

  @override
  Widget build(BuildContext context) {
    return FxScaffold(body: _body(context), title: "List Item", backgroundColor: Colors.white);
  }

  Widget _body(BuildContext context) {
    return ListView(
      children: [
        const Text("只有一个文本的 SingleListItem"),
        SingleListItem("SingleListItem",showLine: true, lineLeftPadding: 15, onTap: () {  }),
        const Text("左右文本的 LeftRightTextItem"),
        const LeftRightTextItem(
          title: "left",
          content: "right",
          showLine: true,
          lineLeftPadding: 15,
        ),
        const Text("左文本右输入的 TextInputItem"),
        Container(color: Colors.black12,height: 0.5),
        const TextInputItem(name:"左文本",hint: "请输入内容", showLine: true,),
        TextInputItem(
          name: "左文本",
          hint: "请输入内容",
          controller: TextEditingController()..text = "可换行内容内容内容内容内容内容内容内容内容内容内容",
          maxLines: null,
          showLine: true,
          // textFieldHeight: 80,
          // height: 80,
        ),
        TextInputItem(
          name: "左文本",
          hint: "请输入内容",
          controller: TextEditingController()..text = "提示在左上角 高文本域 可换行内容内容内容内容内容内容内容内容内容内容内容",
          maxLines: null,
          crossAxisAlignment: CrossAxisAlignment.start,
          textFieldHeight: 80,
          height: 38,
          showLine: true,
        ),
        TextInputItem(
          backgroundColor: Colors.red,
          name: "左文本111111",
          hint: "请输入内容",
          controller: TextEditingController()..text = "提示在左上角 高文本域 可换行",
          maxLines: null,
          crossAxisAlignment: CrossAxisAlignment.start,
          showLine: true,
          // height: 80,
        ),
        const TextInputItem(name:"禁止输入",hint: "禁止输入", showLine: true, disabled: true),
        const Text("左文本右选择的 TextSelectItem"),
        TextSelectItem(
          name: "左文本",
          hint: "请选择内容",
          controller: select,
          arrow: true,
          onTap: () {
            _onStatusPressed(context);
          },
        ),
        TextSelectItem(
          name: "左文本",
          hint: "请选择内容 没有点击事件",
          controller: select,
          arrow: true,
          onTap: null,
        ),
        const TextSelectItem(
          name: "左文本",
          hint: "请选择内容 没有点击事件",
          value: "可复制文本ddddddd",
          valueCopy: true,
          arrow: false,
          onTap: null,
        ),
        TextSelectItem(
          name: "左文本2",
          value: "",
          hint: "请选择内容2",
          arrow: false,
          showLine: true,
          onTap: () {
            ToastUtil.showToast("点击选择文本2");
          },
        ),
        TextSelectItem(
          name: "左文本333333",
          value: "长文本a7fff97d2cb57cfa4e835bc5d3e69f9bead90731b8dde6519933c790f57f3a73点击开始呼叫，将拨打我处中转号码170xxxxxxxx，该号码会有所变化",
          hint: "请选择内容3",
          arrow: false,
          showLine: true,
          onTap: () {
            ToastUtil.showToast("点击选择文本3");
          },
        ),
        TextSelectItem(
          name: "左文本444444",
          value: "长文本a7fff97d2cb57cfa4e835bc5d3e69f9bead90731b8dde6519933c790f57f3a73点击开始呼叫，将拨打我处中转号码170xxxxxxxx，该号码会有所变化",
          hint: "请选择内容4",
          showLine: true,
          onTap: () {
            ToastUtil.showToast("点击选择文本4");
          },
        ),
        TextSelectItem(
          name: "左文本555555",
          value: "长文本a7fff97d2cb57cfa4e835bc5d3e69f9bead90731b8dde6519933c790f57f3a73点击开始呼叫，将拨打我处中转号码170xxxxxxxx，该号码会有所变化",
          hint: "请选择内容5",
          crossAxisAlignment: CrossAxisAlignment.start,
          arrow: false,
          showLine: true,
          onTap: () {
            ToastUtil.showToast("点击选择文本5");
          },
        ),
        TextSelectItem(
          name: "左文本66666",
          value: "长文本a7fff97d2cb57cfa4e835bc5d3e69f9bead90731b8dde6519933c790f57f3a73点击开始呼叫，将拨打我处中转号码170xxxxxxxx，该号码会有所变化",
          hint: "请选择内容6",
          crossAxisAlignment: CrossAxisAlignment.start,
          arrow: true,
          showLine: true,
          onTap: () {
            ToastUtil.showToast("点击选择文本6");
          },
        ),
        TextSelectItem(
          name: "左文本77777",
          value: "长文本a7fff97d2cb57cfa4e835bc5d3e69f9bead90731b8dde6519933c790f57f3a73点击开始呼叫，将拨打我处中转号码170xxxxxxxx，该号码会有所变化",
          hint: "请选择内容7",
          arrowWidget: const Padding(
            padding: EdgeInsets.symmetric(vertical: 14),
            child: Icon(
              Icons.account_circle_rounded,
              size: 18,
              color: Colors.blue,
            ),
          ),
          crossAxisAlignment: CrossAxisAlignment.start,
          arrow: true,
          showLine: true,
          onTap: () {
            ToastUtil.showToast("点击选择文本7");
          },
        ),
      ],
    );
  }

  _onStatusPressed(BuildContext context) async {
    String? res = await showSelectBottomSheet<String,String,String>(
      context,
      list: ["正常", "停用"],
      useSafeArea: true,
      selectedMapper: (List<String> list) {
        return list.join();
      },
    );
    if(res.isNullOrEmpty) return;
    select.value = res!;
  }
}
